package com.jsbj.user.controller;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jsbj.base.ResultBean;
import com.jsbj.framework.controller.BaseController;
import com.jsbj.service.SysProjectService;
import com.jsbj.user.entities.SysProject;
import com.jsbj.user.entities.SysTenant;
import com.jsbj.user.service.ISysProjectService;
import com.jsbj.user.vo.ProListVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 项目表 前端控制器
 * </p>
 *
 * @author jsbj
 * @since 2022-03-07
 */
@RestController
@RequestMapping("/sys-project")
@Api(value = "项目信息", description = "获取项目信息", tags = "获取项目信息")
@ApiIgnore
public class SysProjectController extends BaseController {

    @Autowired
    private ISysProjectService sysProjectService;
    @Autowired
    private SysProjectService projectService;

    @ApiOperation("根据用户id+租户编码查询该租户下所有有权限的项目")
    @ApiImplicitParam(name = "inputParam", value = "用户登录id", required = true)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysProject.class)})
    @PostMapping("/getByUserIdAndTenant")
    public ResultBean<List<SysProject>> getByUserIdAndTenant(@RequestBody String inputParam) {
        JSONObject object = JSONObject.parseObject(inputParam);
        return new ResultBean<List<SysProject>>(sysProjectService.getByUserIdAndTenant(object));
    }

    @ApiOperation("根据用户id+租户编码查询该租户下所有有权限的项目（分页）")
    @ApiImplicitParam(name = "inputParam", value = "用户登录id", required = true)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysProject.class)})
    @PostMapping("/getByUserIdAndTenantByPage")
    public Page<SysProject> getByUserIdAndTenantByPage(@RequestBody String inputParam) {
        JSONObject object = JSONObject.parseObject(inputParam);
        return sysProjectService.getByUserIdAndTenantByPage(object);
    }

    @ApiOperation("通过用户id查询项目列表")
    @PostMapping("/getProjectInfoByUserId")
    public ResultBean<List<SysProject>> getProjectInfoByUserId(@RequestParam String userId) {
        return new ResultBean<List<SysProject>>(sysProjectService.getProjectInfoByUserId(userId));
    }

    @ApiOperation("通过项目编码查询项目详情")
    @PostMapping("/getProjectInfoByTenatCode")
    public ResultBean<SysProject> getProjectInfoByTenatCode(@RequestParam String tenantCode) {
        return new ResultBean<SysProject>(sysProjectService.getProjectInfoByTenatCode(tenantCode));
    }

    @ApiOperation("通过项目编码查询项目详情")
    @PostMapping("/api/getProjectInfoByTenatCodeO")
    public ResultBean<SysProject> getProjectInfoByTenatCodeO(@RequestParam String tenantCode) {
        return new ResultBean<SysProject>(projectService.getProjectInfoByTenatCode(tenantCode));
    }

    @ApiOperation("通过用户id、项目状态、项目名称查询项目列表")
    @PostMapping("/getProjectInfoByUserIdStatusProName")
    public ResultBean<ProListVo> getProjectInfoByUserIdStatusProName(@RequestParam String userId, @RequestParam String status, @RequestParam String proName) {
        return new ResultBean<ProListVo>(sysProjectService.getProjectInfoByUserIdStatusProName(userId,status,proName));
    }

    @ApiOperation("查询拥有某个系统的项目")
    @ApiImplicitParam(name = "systemCode", value = "系统code", required = true)
    @ApiResponses({@ApiResponse(code = 200, message = "请求成功", response = SysTenant.class)})
    @GetMapping("/api/getBySystemCode")
    public ResultBean<List<SysProject>> getBySystemCode(@RequestParam String systemCode) {
        return new ResultBean<>(sysProjectService.getBySystemCode(systemCode));
    }

    @PostMapping("/selectProjectInfoByMenuCode")
    public List<Map<String, Object>> selectProjectInfoByMenuCode(@RequestParam String menuCode) {
        return sysProjectService.selectProjectInfoByMenuCode(menuCode);
    }

    @ApiOperation("更新项目状态")
    @PostMapping("/updateProStatus")
    public ResultBean<Integer> updateProStatus(@RequestParam String proCode, @RequestParam String status, @RequestParam String userId) {
        return new ResultBean<Integer>(sysProjectService.updateProStatus(proCode,status,userId));
    }

}

